#include "connection.h"
#include "listsubject.h"
#include "ui_listsubject.h"

ListSubject::ListSubject(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ListSubject)
{
    ui->setupUi(this);

    tblSubject = new QSqlTableModel(this);
    tblSubject->setTable("\"CSUBJECT\"");
    tblSubject->select();

    ui->tableSubject->setModel(tblSubject);

    setNameFields();
}

ListSubject::~ListSubject()
{
    delete ui;
}

void ListSubject::setNameFields()
{

    tblSubject->setHeaderData(subject_name, Qt::Horizontal, tr("Subject"));
    tblSubject->setHeaderData(subject_namefull, Qt::Horizontal, tr("Subject full"));

    ui->tableSubject->setSelectionMode(QAbstractItemView::SingleSelection);
    ui->tableSubject->setSelectionBehavior(QAbstractItemView::SelectRows);
    ui->tableSubject->setEditTriggers(QAbstractItemView::NoEditTriggers);

    ui->tableSubject->setColumnHidden(subject_id, true);

    ui->tableSubject->resizeColumnsToContents();

    QHeaderView *header = ui->tableSubject->horizontalHeader();
    header->setStretchLastSection(true);
}
